package com.xpgk.mvc.organization;

import java.util.Date;

import com.jfinal.core.Controller;
import com.jfinal.kit.StrKit;
import com.jfinal.log.Log;
import com.xpgk.mvc.base.BaseValidator;
import com.xpgk.mvc.user.User;
import com.xpgk.tools.ToolDateTime;
import com.xpgk.tools.ToolRandoms;

@SuppressWarnings({ "unused" })
public class OrganizationValidator extends BaseValidator {

	private static final Log log = Log.getLog(OrganizationValidator.class);


	protected void validate(Controller controller) {
		String actionKey = getActionKey();
		if (actionKey.equals("/organization/addOrgan")) {

			 vali();
			 if(StrKit.notBlank(controller.getPara("user.username"))){
				User oldUser = User.cacheGetByUserName(controller.getPara("user.username"));
				if(null != oldUser){
					addError("msg", "用户名已存在!");
				}
			}
			/* else{
				addError("msg", "请填写代理人用户名!");
			}*/

		} else if (actionKey.equals("/organization/upOrgan")) {

			// 验证参数
			 vali();
			 if(StrKit.notBlank(controller.getPara("user.username")) && StrKit.notBlank(controller.getPara("user.ids"))){
				User oldUser = User.cacheGetByUserName(controller.getPara("user.username"));
				if(null != oldUser && !controller.getPara("user.ids").equals(oldUser.getPKValue())){
					addError("msg", "用户名已存在!");
				}
			}
			/* else{
				addError("msg", "请填写代理人用户名!");
			}*/
			 
		}
	}

	protected void vali() {
		//validateString("organization.xzqh", 32, 32, "msg", "请选择行政区划!");
	/*	if (!StrKit.notBlank(controller.getPara("user.mobile"))){
			//validateMobile("user.mobile", "msg", "请填写正确的电话号码!");
			addError("msg", "请填写手机号码!");
		}
		validateString("user.name", 1, 32, "msg", "请填写代理人姓名!");
		if(!Organization.zb.equals(controller.getPara("organization.ids"))){
			//validateString("organization.priceIds", 32, 32, "msg", "请选择价格表!");
		}
	//	validateString("organization.mangerIds", 32, 32, "msg", "请选择市场负责人!");
		validateString("organization.name", 1, 18, "msg", "请填写名称!");*/
		
	}

	protected void handleError(Controller controller) {
		controller.renderJson();
	}

}
